# -*- coding=utf-8 -*-
# @time:2021/8/7
# @phone:15874198829
# @author:码尚教育_星瑶

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy

"""
滑屏操作
"""

desired_caps = {
    "automationName": "UiAutomator2",  # 默认框架
    "platformName": "Android",  # 指定操作系统
    "platformVersion": "5.1.1",  # 指定系统版本
    "deviceName": "127.0.0.1:62001",  # 指定设备名称
    "appPackage": "com.tal.kaoyan",  # 被操作的应用程序包名
    "appActivity": "com.tal.kaoyan.ui.activity.SplashActivity",  # 启动页面
    "noReset": False  # 为true 不重置  为false 重置
}
# 发送指令给appium server
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

# 点击取消
el_cancel = driver.find_element(MobileBy.ID, "android:id/button2")
el_cancel.click()

# 实现滑屏
# 获取整个app屏幕的大小
size = driver.get_window_size()
x = size["width"]
y = size["height"]

# 左滑2次
for i in range(0, 2):
    driver.swipe(start_x=x * 0.9, end_x=x * 0.2, start_y=y * 0.8, end_y=y * 0.8, duration=1000)
print("实现左滑两次")
# 上滑
# 下滑
# 右滑
